$(function () {
    $('.div11_span2').on('click', function () {
        $('.div11_box5').show().removeClass('lightSpeedOut').addClass('animated lightSpeedIn');//.fadeIn();
    })
    $('.div11close').on('click', function () {
        $('.div11_box5').removeClass('lightSpeedIn').addClass('animated lightSpeedOut');
        setTimeout(function () {
            $('.div11_box5').hide();
        }, 400)
    })
    $('.div11_span1').on('click', function () {
        $('.div11_date').show().removeClass('lightSpeedOut').addClass('animated lightSpeedIn');//.fadeIn();
    })
    $('.divdateclose').on('click', function () {
        $('.div11_date').removeClass('lightSpeedIn').addClass('animated lightSpeedOut');
        setTimeout(function () {
            $('.div11_date').hide();
        }, 400)
    });

    //table表格滚动js by  cy
    function scrollDiv() {
        var right_div2_left = $("#right_div2").scrollLeft();
        $("#right_div1").scrollLeft(right_div2_left);
    }

// 百度地图API功能
//     var map = new BMap.Map("mapla");    // 创建Map实例
//     map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
//     //添加地图类型控件
//     map.addControl(new BMap.MapTypeControl({
//         mapTypes:[
//             BMAP_NORMAL_MAP,
//             BMAP_HYBRID_MAP
//         ]}));
//     map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
//     map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
//    mapline('mapla', ['北京天安门', '北京黄村'], '116.37811,39.851817', '冷库一', '司机    王师明' +
//        '<br/>车牌 鄂A0313' +
//        '<br/>订单 3单' +
//        '<br/>品规数 5个' +
//        '<br/>客户 3家' +
//        '<br/>件数 28件' +
//        '<br/>监控温度 2.1℃' +
//        '<br/>监控温度 60%' +
//        '<br/>车外温度 30℃')
//
//     $('#idmaphide').hide();

    // 车辆温度曲线
    var myChart = document.getElementById('echart-3');
    var hours = ['9:30', '9:30', '9:30', '9:30', '9:30', '9:30', '9:30',
        '9:30', '9:30', '9:30', '9:30', '9:30',
        '9:30', '9:30', '9:30', '9:30', '9:30'];
    var days = ['鄂A0314', '鄂A0314', '鄂A0314'];

    var data = [
        [0, 0, 5], [0, 1, 1], [0, 7, 0], [0, 8, 0], [0, 9, 0], [0, 10, 0], [0, 11, 2], [0, 12, 4], [0, 13, 1], [0, 19, 4], [0, 23, 5],
        [1, 0, 7], [1, 1, 0], [1, 2, 0], [1, 3, 0], [1, 4, 0], [1, 10, 5], [1, 11, 2], [1, 12, 2], [1, 16, 6],
        [2, 0, 1], [2, 1, 1], [2, 13, 1], [2, 14, 1], [2, 15, 1], [2, 16, 1], [2, 22, 1], [2, 23, 1]
    ];

    //用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
    var resizeWorldMapContainer = function () {
        myChart.style.height = days.length * 80 + 'px';
    };
    // //设置容器高宽
    resizeWorldMapContainer();
    // 基于准备好的dom，初始化echarts实例
    var myChart3 = echarts.init(myChart);

    app.title = '单轴散点图';

    option = {
        tooltip: {
            position: 'top'
        },
        title: [],
        singleAxis: [],
        series: [],
        yAxis: []
    };

    echarts.util.each(days, function (day, idx) {
        option.title.push({
            textBaseline: 'middle',
            top: (idx + 1) * 100 / 7 + '%',
            text: day,
            textStyle: {
                color: '#373737',
                fontSize: 14,
            }
        });
        // option.yAxis.push({
        //     gridIndex:idx,
        // });
        option.singleAxis.push({
            left: 100,
            type: 'category',
            boundaryGap: false,
            data: hours,
            top: (idx * 100 / 7 + 13) + '%',
            height: (100 / 7 - 10) + '%',
            axisLabel: {
                show: false,
                margin: 15
            },
            axisTick: {
                show: false
            },
            axisLine: {
                show: false,
            },
            nameTextStyle: {
                lineHeight: 80,
            },
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#999',
                    type: 'dotted'
                    // type: 'dashed'
                }
            },
        });
        option.series.push({
            singleAxisIndex: idx,
            coordinateSystem: 'singleAxis',
            type: 'scatter',
            data: [],
            yAxisIndex: idx,
            symbolSize: function (dataItem) {
                return dataItem[1] * 4;
            }
        });
    });

    echarts.util.each(data, function (dataItem) {
        option.series[dataItem[0]].data.push([dataItem[1], dataItem[2]]);
    });

    option.singleAxis[days.length - 1].axisLabel.show = true;

    myChart3.setOption(option);

    maplines();

})

function maplines() {
    var list = [{
        stp: '116.380967, 39.913285', //起点
        endp: '116.424374, 39.914668', // 终点
        runp: '116.398585,39.914064', // 行驶点
        cartitle: '司机    王师明' +
        '<br/>车牌 鄂A0313' +
        '<br/>订单 3单' +
        '<br/>品规数 5个' +
        '<br/>客户 3家' +
        '<br/>件数 28件' +
        '<br/>监控温度 2.1℃' +
        '<br/>监控温度 60%' +
        '<br/>车外温度 30℃',
    }, {
        stp: '116.380967, 39.913285', //起点
        endp: '116.380967, 39.953285', // 终点
        runp: '116.380125,39.933211', // 行驶点
        cartitle: '司机    王师明' +
        '<br/>车牌 鄂A0313' +
        '<br/>订单 3单' +
        '<br/>品规数 5个' +
        '<br/>客户 3家' +
        '<br/>件数 28件' +
        '<br/>监控温度 2.1℃' +
        '<br/>监控温度 60%' +
        '<br/>车外温度 30℃',
    }];
    var map = new BMap.Map("mapla");
    // 百度地图API功能
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 10);
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    var bounds = null;
    var linesPoints = null;
    var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/Mario.png", new BMap.Size(32, 70), {imageOffset: new BMap.Size(0, 0)});


    for (let i = 0; i < list.length; i++) {
        var _stp = list[i].stp;
        _sp = _stp.split(',')[0];
        _st = _stp.split(',')[1];
        var _endp = list[i].endp;
        _ep = _endp.split(',')[0];
        _et = _endp.split(',')[1];
        var _runp = list[i].runp;
        _runsp = _runp.split(',')[0];
        _runst = _runp.split(',')[1];
        var stp = new BMap.Point(_sp, _st);    // 起点
        var endp = new BMap.Point(_ep, _et);    // 起点
        initLine(stp, endp);
        var runp = new BMap.Point(_runsp, _runst);    // 起点
        var labeltip = addtexts(_runsp, _runst, list[i].cartitle);
        myIcon = new BMap.Icon('images/i_end.png', new BMap.Size(22, 22));
        var runMark = new BMap.Marker(runp, {icon: myIcon});
        // var myIcon = new BMap.Icon("http://lbsyun.baidu.com/jsdemo/img/fox.gif", new BMap.Size(300,157));
        // var marker2 = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
        console.log(runp);
        map.addOverlay(runMark);
        runMark.addEventListener('click', function () {
            if (!labeltip.show) {
                map.addOverlay(labeltip);
            } else {
                map.removeOverlay(labeltip);
            }
            labeltip.show = !labeltip.show;
        })
    }


    function initLine(stp, endp) {
        bounds = new Array();
        linesPoints = new Array();
        // map.clearOverlays();                                                    // 清空覆盖物
        var driving3 = new BMap.DrivingRoute(map, {onSearchComplete: drawLine});  // 驾车实例,并设置回调
        driving3.search(stp, endp);                                       // 搜索一条线路
    }

    function drawLine(results) {
        console.log(results)
        var opacity = 0.45;
        var planObj = results.getPlan(0);
        var b = new Array();
        var addMarkerFun = function (point, imgType, index, title) {
            var url;
            var width;
            var height
            var myIcon;
            if (imgType == 0) {
                myIcon = new BMap.Icon('images/i_e.png',new BMap.Size(22, 22));
            } else if (imgType == 1) {
                myIcon = new BMap.Icon('images/i_start.png', new BMap.Size(22, 22));
            } else {
                url = "http://lbsyun.baidu.com/jsdemo/img/trans_icons.png";
                width = 22;
                height = 25;
                var d = 25;
                var cha = 0;
                var jia = 0
                if (index == 2) {
                    d = 21;
                    cha = 5;
                    jia = 1;
                }
                myIcon = new BMap.Icon(url, new BMap.Size(width, d), {
                    offset: new BMap.Size(10, (11 + jia)),
                    imageOffset: new BMap.Size(0, 0 - index * height - cha)
                });
            }

            var marker = new BMap.Marker(point, {icon: myIcon});
            if (title != null && title != "") {
                marker.setTitle(title);
            }
            // 起点和终点放在最上面
            if (imgType == 1) {
                marker.setTop(true);
            }
            map.addOverlay(marker);
        }
        var addPoints = function (points) {
            for (var i = 0; i < points.length; i++) {
                bounds.push(points[i]);
                b.push(points[i]);
            }
        }
        // 绘制驾车步行线路
        for (var i = 0; i < planObj.getNumRoutes(); i++) {
            var route = planObj.getRoute(i);
            if (route.getDistance(false) <= 0) {
                continue;
            }
            addPoints(route.getPath());
            // 驾车线路
            if (route.getRouteType() == BMAP_ROUTE_TYPE_DRIVING) {
                map.addOverlay(new BMap.Polyline(route.getPath(), {
                    strokeColor: "#4fa1a4",
                    strokeOpacity: 1,
                    strokeWeight: 4,
                    enableMassClear: true
                }));
            } else {
                // 步行线路有可能为0
                map.addOverlay(new BMap.Polyline(route.getPath(), {
                    strokeColor: "#4fa1a4",
                    strokeOpacity: 0.75,
                    strokeWeight: 4,
                    enableMassClear: true
                }));
            }
        }
        map.setViewport(bounds);
        // 终点
        addMarkerFun(results.getEnd().point, 0, 1);
        // 开始点
        addMarkerFun(results.getStart().point, 1, 0);
        linesPoints[linesPoints.length] = b;
    }


    function addtexts(p, t, text) {
        var opts = {
            position: new BMap.Point(p, t),
            offset: new BMap.Size(20, -20)
        }
        var label = new BMap.Label(text, opts);
        label.setStyle({
            color: "#fff",
            fontSize: "14px",
            lineHeight: "20px",
            border: '0px',
            padding: '4px',
            background: 'rgba(0,89,130,0.5)'
        });
        label.show = 0;
        return label;
    }
}
